﻿// Copyright 2014 Zenasoft.  All rights reserved.
//
// This file is part of Hyperstore.
//
//    Hyperstore is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Hyperstore is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Hyperstore.  If not, see <http://www.gnu.org/licenses/>.

#region Imports

using System;
using System.Linq;
using System.Threading.Tasks;

#endregion

namespace Hyperstore.Modeling.Utils
{
    /// <summary>Provides access to an already completed task.</summary>
    /// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks>
    internal static class CompletedTask
    {
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Gets a completed Task.
        /// </summary>
        ///-------------------------------------------------------------------------------------------------
        public static readonly Task Default = CompletedTask<object>.Default;
    }

    /// <summary>Provides access to an already completed task.</summary>
    /// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks>
    internal static class CompletedTask<TResult>
    {
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Gets a completed Task.
        /// </summary>
        ///-------------------------------------------------------------------------------------------------
        public static readonly Task<TResult> Default;

        /// <summary>Initializes a Task.</summary>
        static CompletedTask()
        {
            Default = Task.FromResult<TResult>(default(TResult));
        }
    }
}